#include "../mqserver/mq_binding.hpp"
#include "../mqcommon/mq_helper.hpp"
#include <gtest/gtest.h>

wsmq::BindingManager::ptr bdmp;

class bindingTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        bdmp = std::make_shared<wsmq::BindingManager>("./data/mata.db");
    }
    virtual void TearDown() override
    {
        // wsmq::FileHelper::removeDirectory("./data/mata.db");
    }
};

TEST(bindingTest, bindTest)
{
    bdmp->bind("news.music.#", "exchange1", "queue1", true);
    bdmp->bind("news.sport.#", "exchange1", "queue2", true);
    bdmp->bind("news.music.pop", "exchange2", "queue1", true);
    bdmp->bind("news.sport.football", "exchange2", "queue2", true);
    ASSERT_EQ(bdmp->size(), 4);
}

// TEST(bindingTest, selectTest)
// {
//     ASSERT_EQ(bdmp->exists("exchange1", "queue1"), true);
//     ASSERT_EQ(bdmp->exists("exchange1", "queue2"), true);
//     ASSERT_EQ(bdmp->exists("exchange2", "queue1"), true);
//     ASSERT_EQ(bdmp->exists("exchange2", "queue2"), true);
//     auto bp = bdmp->getBinding("exchange1", "queue1");
//     ASSERT_NE(bp.get(), nullptr);
//     ASSERT_EQ(bp->_binding_key, "news.music.#");
//     ASSERT_EQ(bp->_exchange_name, "exchange1");
//     ASSERT_EQ(bp->_queue_name, "queue1");
    
// }

// TEST(bindingTest, selectExchangeTest)
// {
//     wsmq::MsgQueueBindingMap qmap =  bdmp->getExchangeBindings("exchange1");
//     ASSERT_EQ(qmap.size(), 2);
//     ASSERT_NE(qmap.find("queue1"), qmap.end());
//     ASSERT_EQ(qmap.find("queue3"), qmap.end());
//     ASSERT_NE(bdmp->exists("exchange1", "queue1"), true);
//     ASSERT_NE(bdmp->exists("exchange1", "queue2"), true);

// }

// TEST(bindingTest, removeExchangeTest)
// {
//     bdmp->removeExchangeBind("exchange1");
//     ASSERT_EQ(bdmp->size(), 2);
// }

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new bindingTest);
    return RUN_ALL_TESTS();
}